
package com.bear.cmcc.NetTestHTTP.component;

import com.baidu.location.BDLocation;
import com.baidu.location.BDLocationListener;
import com.baidu.location.LocationClient;
import com.bear.cmcc.NetTestHTTP.NetworkTestApp;
import com.bear.cmcc.NetTestHTTP.R;
import com.bear.cmcc.NetTestHTTP.constant.LocationConstant;

import android.content.Context;
import android.content.Intent;

/**
 * 定位成功，会把地理位置信息保存到 NetworkTestApp中。
 * 
 * @author suchangjun
 */
public class MyLocationListenner implements BDLocationListener {
    private Context context;

    private String message;

    Intent intent = new Intent(LocationConstant.ACTION_LOCATION_BROADCASE);

    public MyLocationListenner(Context context) {
        if (context != null) {
            this.context = context;
            message = context.getString(R.string.you_current_loca);
        }
    }

    @Override
    public void onReceiveLocation(BDLocation location) {
        try {

            if (location == null) {
                return;
            } else {
//                MyCommonUtil.showMessage(context, message + location.getAddrStr());
                intent.putExtra(LocationConstant.IS_SUCCESS, true);
                intent.putExtra(LocationConstant.PROVINCE, location.getProvince());
                intent.putExtra(LocationConstant.CIRY, location.getCity());
                intent.putExtra(LocationConstant.VILLAGE, location.getDistrict());
                intent.putExtra(LocationConstant.STREET, location.getStreet());
                intent.putExtra(LocationConstant.ALL, location.getAddrStr());
                NetworkTestApp.getApp().setProviceName(location.getProvince());
                NetworkTestApp.getApp().setCityName(location.getCity());
                NetworkTestApp.getApp().setVillage(location.getDistrict());
                NetworkTestApp.getApp().setStreet(location.getStreet());
                NetworkTestApp.getApp().setLatitude(location.getLatitude());
                NetworkTestApp.getApp().setLongitude(location.getLongitude());
                context.sendBroadcast(intent);
                LocationClient mLocClient = NetworkTestApp.getApp().getmLocationClient();
                mLocClient.stop();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

    public void onReceivePoi(BDLocation poiLocation) {
        if (poiLocation == null) {
            return;
        }
    }
}
